    program mean_robinhood_holders
    character*5 ticker
    character*8 cusp
    integer(kind=8) nshrs,nvalue,jvalue,ivol,numshrs
    dimension nep(5000),numhld(5000)
!      open(unit=10,file='e:\FIS_duration\episode_data_with_robinhood.txt')
!      open(unit=99,file='e:\FIS_duration\avg_robinhood_hold.txt')
      open(unit=10,file='e:\FIS_duration\episode_data_with_robinhood_rep.txt')
      open(unit=99,file='e:\FIS_duration\avg_robinhood_hold_rep.txt')
      iend=0
      ii=0 
1     ii=ii+1      
2     read(10,1000,end=100)nep(ii),jast,jdate,cusp,ticker,itickt,numshrs,age,favg,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs,numhld(ii)     
1000  format(1x,i4,2(1x,i8),1x,a8,2x,a5,5x,i9,1x,i14,2(1x,f11.4),1x,i5,1x,f9.2,1x,i10,1x,f10.6,1x,i9,1x,f9.6,1x,f6.2,1x,i13,1x,i7) 
      if(numhld(ii).lt.0) go to 2
      if(nep(ii).eq.nep(1)) go to 1
5     icnt=ii-1
      avghld=0.
      do 10 k=1,icnt
10    avghld=avghld+float(numhld(k))/float(icnt)
      write(6,9900)nep(1),icnt,avghld
      write(99,9900)nep(1),icnt,avghld
9900  format(1x,i4,1x,i4,1x,f9.2)      
50    nep(1)=nep(ii)
      numhld(1)=numhld(ii)
      ii=1
      go to 1
100   iend=iend+1
      if(iend.eq.1) go to 5 
      stop

    end program mean_robinhood_holders
